<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/template.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:define name="body">
        <h:form id="form" styleClass="form list">
            <p:fieldset legend="User Control" id="user_create"  >
                <c:if test="#{userController.allowedGroups('2')}">
                    <p:commandButton value="New User" icon="ui-icon-plus" action="#{userController.prepareCreate}" />
                </c:if>
                <p:separator/>
                <p:dataTable id="users"
                             styleClass="data"
                             var="user"
                             rowKey="#{user}"
                             value="#{userController.users}"
                             selection="#{userController.current}"
                             selectionMode="single"
                             rows="8"
                             paginator="#{userController.users.size() gt 8}"
                             rowStyleClass="#{user.userLive ? 'active' : 'inactive'}"
                             >
                    <f:facet name="header">
                        <h:outputText value="Users"></h:outputText>
                    </f:facet>
                    <p:column sortBy="#{user.userLogin}" filterBy="#{user.userLogin}">
                        <f:facet name="header">
                            <h:outputText value="Login"/>
                        </f:facet>
                        <h:outputText value="#{user.userLogin}"/>
                    </p:column>
                    <p:column sortBy="#{user.userEmail}" filterBy="#{user.userEmail}">
                        <f:facet name="header">
                            <h:outputText value="Email"/>
                        </f:facet>
                        <h:outputText value="#{user.userEmail}"/>
                    </p:column>
                    <p:column sortBy="#{user.userLive}" filterBy="#{user.userLive}" style="text-align: center" >
                        <f:facet name="header">
                            <h:outputText value="Active"/>
                        </f:facet>
                        <p:graphicImage value="/resources/images/syscon/user_#{user.userLive}.png" alt="#{user.userLive}" title="#{user.userLive}" height="32" width="32" />
                    </p:column>
                    <p:column sortBy="#{user.userCreation}" filterBy="#{user.userCreation}" >
                        <f:facet name="header">
                            <h:outputText value="Last update"/>
                        </f:facet>
                        <h:outputText value="#{user.userCreation}">
                        </h:outputText>
                    </p:column>
                    <f:facet name="footer">
                        <h:outputText id="rowCount"
                                      value="Total number of records: #{userController.users.size()}" />
                        <br />
                        <p:commandButton ajax="false" action="#{userController.prepareCreate}" value="New" icon="ui-icon-plus" rendered="#{userController.users.size() lt 1}"/>
                    </f:facet>
                </p:dataTable>
                <c:if test="#{userController.allowedGroups('2')}">
                    <p:contextMenu for="users" >
                        <p:menuitem value="Edit" icon="ui-icon-pencil"   action="#{userController.prepareEdit}" />
                        <p:menuitem value="Block Access" icon="ui-icon-close" actionListener="#{userController.blockUser()}" update=":form:"/>
                        <p:menuitem value="Allow Access" icon="ui-icon-star" actionListener="#{userController.activeUser()}" update=":form:"/>
                        <p:menuitem value="View" icon="ui-icon-search" action="#{userController.prepareView}"/>
                        <c:if test="#{userController.allowedGroups('1')}">
                            <p:menuitem value="Destroy" icon="ui-icon-close" action="#{userController.destroy()}" update=":form:"/>
                        </c:if>
                        <c:if test="#{userController.allowedGroups('2')}">
                            <p:menuitem value="New" icon="ui-icon-plus" action="#{userController.prepareCreate}" />
                        </c:if>
                    </p:contextMenu>
                </c:if>
            </p:fieldset>
        </h:form>
    </ui:define>
    <ui:define name="right">
        <h:form>
            <h:panelGrid columns="2">
                <p:panel header="Export All Data">
                    <h:commandLink>
                        <p:graphicImage value="../resources/images/syscon/excel.png" />
                        <p:dataExporter type="xls" target=":form:users" fileName="users" />
                    </h:commandLink>

                    <h:commandLink>
                        <p:graphicImage value="../resources/images/syscon/pdf.png" />
                        <p:dataExporter type="pdf" target=":form:users" fileName="users"/>
                    </h:commandLink>

                    <h:commandLink>
                        <p:graphicImage value="../resources/images/syscon/csv.png" />
                        <p:dataExporter type="csv" target=":form:users" fileName="users" />
                    </h:commandLink>

                    <h:commandLink>
                        <p:graphicImage value="../resources/images/syscon/xml.png" />
                        <p:dataExporter type="xml" target=":form:users" fileName="users" />
                    </h:commandLink>
                </p:panel>
                <p:panel header="Export Page Data" rendered="#{userController.users.size() gt 8}">
                    <h:commandLink>
                        <p:graphicImage value="../resources/images/syscon/excel.png" />
                        <p:dataExporter type="xls" target=":form:users" fileName="users" pageOnly="true"/>
                    </h:commandLink>

                    <h:commandLink>
                        <p:graphicImage value="../resources/images/syscon/pdf.png" />
                        <p:dataExporter type="pdf" target=":form:users" fileName="users" pageOnly="true"/>
                    </h:commandLink>

                    <h:commandLink>
                        <p:graphicImage value="../resources/images/syscon/csv.png" />
                        <p:dataExporter type="csv" target=":form:users" fileName="users" pageOnly="true"/>
                    </h:commandLink>

                    <h:commandLink>
                        <p:graphicImage value="../resources/images/syscon/xml.png" />
                        <p:dataExporter type="xml" target=":form:users" fileName="users" pageOnly="true"/>
                    </h:commandLink>
                </p:panel>
            </h:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>
